import request from '@/utils/http'

export interface GetRenWuListResult {
  craftNodeId: string
  machineDocumentId: string
  machineName: string
  machineNo: number
  tsId: number
  shiftName: string
  teamSet: string
  personDocumentId: string
  personName: string
  jobTitleRecordId: any
  title: string
  scanTime: string
  ratio: string
  remark: string
  updateTime: any
  state: number
  employeeDutySource: number
}

interface postRenYuanJiaoXiao_XSResult {
  statistics: {
    personDocumentId: string
    personName: string
    scanCnt: number
    jointTimeAvg: any
    breakCntToNext: any
    doffingCnt: number
    doffingTimeAvg: number
    stopTime: number
    stopTimeAvg: number
    efcRun: number
    yarnLength: number
    theoreticalYarnWeight: number
    actualYarnWeight: number
  }[]
  statisticsByMaterial: {
    personDocumentId: string
    personName: string
    byPersonMaterial: {
      materialId: string
      materialName: string
      scanCnt: number
      jointTimeAvg: any
      breakCntToNext: any
      doffingCnt: number
      doffingTimeAvg: number
      stopTime: number
      stopTimeAvg: number
      efcRun?: number
      yarnLength: number
      theoreticalYarnWeight: number
      actualYarnWeight: number
    }[]
  }[]
  detail: {
    tsId: number
    shiftName: string
    teamSet: string
    yarnLength: number
    theoreticalYarnWeight: number
    actualYarnWeight: number
    stopTime: number
    stopTimeAvg: number
    byTsidPerson: {
      personDocumentId: string
      personName: string
      byTsidPersonMaterial: {
        materialId: string
        materialName: string
        scanCnt: number
        jointTimeAvg: any
        breakCntToNext: any
        doffingCnt: number
        doffingTimeAvg: number
        efcRun: number
        stopTime: number
        yarnLength: number
        theoreticalYarnWeight: number
        actualYarnWeight: number
      }[]
    }[]
  }[]
}

interface postYuanGongJiXiaoListResult {
  statistics: {
    personDocumentId: string
    personName: string
    scanCnt: number
    yarnLength: number
    theoreticalYarnWeight: number
    actualYarnWeight: number
    efcRun: any
    stopTime: number
    stopTimeAvg: number
    warningCnt: number
    durationTotal: number
  }[]
  groupdatas: {
    personDocumentId: string
    personName: string
    byPersonMaterial: {
      materialId: string
      materialName: string
      scanCnt: number
      stopTime: number
      stopTimeAvg: number
      efcRun: any
      theoreticalYarnWeight: number
      actualYarnWeight: number
      yarnLength: number
      warningCnt: number
      durationTotal: number
    }[]
  }[]
  detaildatas: {
    tsId: number
    shiftName: string
    teamSet: string
    yarnLength: number
    theoreticalYarnWeight: number
    actualYarnWeight: number
    stopTime: number
    stopTimeAvg: number
    warningCnt: number
    durationTotal: number
    byTsidPerson: {
      personDocumentId: string
      personName: string
      byTsidPersonMaterial: {
        materialId: string
        materialName: string
        scanCnt: number
        stopTime: number
        stopTimeAvg: number
        efcRun: number
        yarnLength: number
        theoreticalYarnWeight: number
        actualYarnWeight: number
        warningCnt: number
        durationTotal: number
      }[]
    }[]
  }[]
}

interface postJiTaiJiaoXiao_XSResult {
  statistics: {
    materialId: string
    materialName: string
    jointCnt: number
    jointTimeTotal: number
    jointTimeAvg: any
    breakCntToNext: number
    doffingCnt: number
    doffingTimeAvg?: number
    dofferTotalTime: number
    efcRun: number
    shiftPowerOns: number
    runtimes: number
    yarnLength: number
    theoreticalYarnWeight: number
    actualYarnWeight: number
    stopTime: number
    stopTimeAvg: number
  }[]
  statisticsByMaterialMachine: {
    machineDocumentId: string
    machineName: string
    machineNo: number
    materialId: string
    materialName: string
    jointCnt: number
    jointTimeTotal: number
    jointTimeAvg: any
    breakCntToNext: number
    doffingCnt: number
    doffingTimeAvg?: number
    dofferTotalTime: number
    efcRun: number
    shiftPowerOns: number
    runtimes: number
    yarnLength: number
    theoreticalYarnWeight: number
    actualYarnWeight: number
    stopTime: number
    stopTimeAvg: number
  }[]
  detail: {
    tsId: number
    shiftName: string
    teamSet: string
    personName: string
    machineDocumentId: string
    machineName: string
    machineNo: number
    materialId: string
    materialName: string
    jointCnt: any
    jointTimeTotal: any
    jointTimeAvg: any
    breakCntToNext: any
    doffingCnt: number
    doffingTimeAvg?: number
    dofferTotalTime: number
    efcRun: number
    shiftPowerOns: number
    runtimes: number
    yarnLength: number
    theoreticalYarnWeight: number
    actualYarnWeight: number
    stopTime: number
    stopTimeAvg: number
  }[]
}

interface postJiTaiJiaoXiaoResult {
  statistics: {
    materialName: string
    shiftPowerOns: number
    runtimes: number
    efcRun: number
    yarnLength: number
    theoreticalYarnWeight: number
    actualYarnWeight: number
    stopTime: number
    stopTimeAvg: number
    warningCnt: number
    durationTotal: number
  }[]
  statisticsByMaterialMachine: {
    machineDocumentId: string
    machineName: string
    machineNo: number
    materialName: string
    shiftPowerOns: number
    runtimes: number
    efcRun: number
    yarnLength: number
    theoreticalYarnWeight: number
    actualYarnWeight: number
    stopTime: number
    stopTimeAvg: number
    warningCnt: number
    durationTotal: number
  }[]
  detail: {
    tsId: number
    shiftName: string
    teamSet: string
    personName: string
    machineDocumentId: string
    machineName: string
    machineNo: number
    materialName: string
    shiftPowerOns: number
    runtimes: number
    efcRun: number
    yarnLength: number
    theoreticalYarnWeight: number
    actualYarnWeight: number
    stopTime: number
    stopTimeAvg: number
    warningCnt: any
    durationTotal: any
  }[]
}

/**
 * ------------------任务管理2----------------
 * 任务认领
 */
export function getRenWuList(data: {
  tsid: number | string
  CraftNodeId: number | string
  jobTitleId: number | string
}) {
  return request.request<GetRenWuListResult[]>({
    url:
      '/api/v3.1/business/employee-scan/by-tsid-craftnodeid?tsid=' +
      data.tsid +
      '&CraftNodeId=' +
      data.CraftNodeId +
      '&JobTitleId=' +
      data.jobTitleId,
    method: 'get'
  })
}

/**
 * 根据班次、工艺节点、区域id，查询车间人工扫码上车记录
 */
export function getRenWuList_qy(data: {
  tsid: number | string
  CraftNodeId: number | string
  areaId: number | string
}) {
  return request.request<GetRenWuListResult[]>({
    url:
      '/api/v3.1/business/employee-scan/by-tsid-craftnodeid-areaid?tsid=' +
      data.tsid +
      '&CraftNodeId=' +
      data.CraftNodeId +
      '&areaId=' +
      data.areaId,
    method: 'get'
  })
}

/**
 * 根据车间，查询所有装有单锭检测的机台和对应的物料
 */
export function postRenWuFeiPei(data) {
  return request.request({
    url: '/api/v3.1/business/employee-scan/from-web',
    method: 'post',
    data
  })
}

/**
 * ------------------绩效考核----------------
 * 根据时间、工种、工艺节点，查询期间上车的员工
 */
export function getRenYuanList(
  data: {
    tsIdStart: string | number
    tsIdEnd: string | number
    jobTitleId: string
    craftNodeId: string
    name: string
  },
  quYuNum: string | number = 0,
  areaValue: string | number
) {
  let url = ''
  if (quYuNum != 1) {
    url =
      '/api/v3.1/business/employee-scan/employee-by-tsid-jobtitleid?tsIdStart=' +
      data.tsIdStart +
      '&tsIdEnd=' +
      data.tsIdEnd +
      '&jobTitleId=' +
      data.jobTitleId +
      '&craftNodeId=' +
      data.craftNodeId +
      '&name=' +
      data.name
  } else {
    url =
      '/api/v3.1/business/employee-scan/employee-by-tsid-jobtitleid-and-area?tsIdStart=' +
      data.tsIdStart +
      '&tsIdEnd=' +
      data.tsIdEnd +
      '&jobTitleId=' +
      data.jobTitleId +
      '&craftNodeId=' +
      data.craftNodeId +
      '&name=' +
      data.name +
      '&areaId=' +
      areaValue
  }
  return request.request<{ personDocumentId: string; employeeCode: string; firstName: string }[]>({
    url: url,
    method: 'get'
  })
}

/**
 * 指定工艺节点、工种、时间范围、员工，查询员工绩效
 */
export function postYuanGongJiXiaoList(data) {
  return request.request<postYuanGongJiXiaoListResult>({
    url: '/api/v3.1/business/employee-scan/performance-by-craftnode-jobtitle-tsid-person',
    method: 'post',
    data
  })
}

/**
 * 指定工艺节点、工种、时间范围、员工、区域，查询员工绩效
 */
export function postYuanGongJiXiaoList_qy(data) {
  return request.request({
    url: '/api/v3.1/business/employee-scan/by-craftnode-jobtitle-tsid-person-area',
    method: 'post',
    data
  })
}

/**
 * 人员管理-任务分配-新增班组人员信息
 */
export function postAddBanZuRenYuanXinXi(data) {
  return request.request({
    url: '/api/v3.1/business/duty-assign-history/employee-department-history',
    method: 'post',
    data
  })
}

/**
 * 人员管理-任务分配-删除班组人员
 */
export function deleteBanZuRenYuan(data) {
  return request.request({
    url:
      '/api/v3.1/business/duty-assign-history/' +
      data.id +
      '/employee-department-history/' +
      data.PersonDocumentId,
    method: 'delete'
  })
}

/**
 * 根据工艺节点、班组、人员获取人员机台看台信息
 */
export function getRenYuanFenPaiDeJiTaiList(data) {
  return request.request({
    url:
      '/api/v3.1/business/duty-assign-history/device-person-info-by-person?personDocumentId=' +
      data.personDocumentId +
      '&teamset=' +
      data.teamset +
      '&craftNodeId=' +
      data.craftNodeId,
    method: 'get'
  })
}

/**
 * 人员管理-任务分配-根据工艺节点获取班组、人员信息
 */
export function getHuoQuBanZuXingXi(data) {
  return request.request({
    url: '/api/v3.1/business/duty-assign-history/employee-department-history/' + data.CraftNodeId,
    method: 'get'
  })
}

/**
 * 人员管理-任务分配-根据工序、班组和模式获取待选员工信息
 */
export function getHuoQuDaiXuanYuanGongList(data) {
  return request.request({
    url:
      '/api/v3.1/business/duty-assign-history/employee-department-history-by-craft-and-team/' +
      data.CraftNodeId +
      '?Teamset=' +
      data.Teamset,
    method: 'get'
  })
}

/**
 * 人员管理-任务分配-更新任务分配信息
 */
export function putRenWuFeiPai(data) {
  return request.request({
    url: '/api/v3.1/business/duty-assign-history/duty-assign-history',
    method: 'put',
    data
  })
}

/**
 * 人员管理-任务分配-更新任务分配信息（带区域的租户）
 */
export function putRenWuFeiPai_qy(data) {
  return request.request({
    url: '/api/v3.1/business/duty-assign-history/duty-assign-history-by-area',
    method: 'put',
    data
  })
}

/**
 * 获取人员排版模式，0-班组分配，2-扫码上车
 */
export function getHuoQuPaiBanMoShi() {
  return request.request<number>({
    url: '/api/v3.1/business/employee-scan/humanresource-model',
    method: 'get'
  })
}

/**
 * 导入员工信息
 */
export function postDaoRuRenYuanXinXi(data) {
  return request.request({
    url: '/api/v3.1/business/person-document/import',
    method: 'post',
    data
  })
}

/**
 * 人员管理-绩效考核-指定工种、时间范围、员工，查询细纱工序员工绩效
 */
export function postRenYuanJiaoXiao_XS(data) {
  return request.request<postRenYuanJiaoXiao_XSResult>({
    url: '/api/v3.1/business/employee-scan/employee-performance-xs',
    method: 'post',
    data
  })
}

/**
 * 人员管理-绩效考核-指定工种、时间范围、员工、区域，查询细纱工序员工绩效
 */
export function postRenYuanJiaoXiao_XS_qy(data) {
  return request.request({
    url: '/api/v3.1/business/employee-scan/employee-performance-xs-by-area',
    method: 'post',
    data
  })
}

/**
 * 人员管理-绩效考核-指定机台、班次，查询员工绩效
 */
export function postJiTaiJiaoXiao(data) {
  return request.request<postJiTaiJiaoXiaoResult>({
    url: '/api/v3.1/business/employee-scan/employee-performance-by-machine',
    method: 'post',
    data
  })
}

/**
 * 人员管理-绩效考核-指定机台、班次，查询细纱工序员工绩效
 */
export function postJiTaiJiaoXiao_XS(data) {
  return request.request<postJiTaiJiaoXiao_XSResult>({
    url: '/api/v3.1/business/employee-scan/employee-performance-by-machine-xs',
    method: 'post',
    data
  })
}

/**
 * 新增辅助任务
 */
export function postXinZengFuZuRenWu(data) {
  return request.request({
    url: '/api/v3.1/business/assist-task/assist-task',
    method: 'post',
    data
  })
}

/**
 * 查询辅助任务
 */
export function getFuZuRenWu() {
  return request.request({
    url: '/api/v3.1/business/assist-task/assist-task-list',
    method: 'get'
  })
}

/**
 * 修改辅助任务
 */
export function putXiuGaiFuZuRenWu(data, id) {
  return request.request({
    url: '/api/v3.1/business/assist-task/' + id + '/assist-task',
    method: 'put',
    data
  })
}

/**
 * 删除辅助任务
 */
export function deleteFuZuRenWu(id) {
  return request.request({
    url: '/api/v3.1/business/assist-task/' + id + '/assist-task',
    method: 'delete'
  })
}
